package com.wc.alorithm_blue_bridge._思维.Q2049;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.ArrayList;

/**
 * @Author congge
 * @Date 2023/11/4 20:40
 * @description 蓝桥勇士
 * https://www.lanqiao.cn/problems/2049/learning/?page=2&first_category_id=1&sort=students_count&second_category_id=8
 */
public class Main {
    public static void main(String[] args) {
        Input sc = new Input();
        int n = sc.nextInt();
        int[] array = new int[n];
        ArrayList<Integer> ans = new ArrayList<>();
        ans.add(0);
        int size = 0;
        int left;
        int right;
        int mid;
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
            if (array[i] > ans.get(size)) {
                ans.add(array[i]);
                size++;
            }else {
                left = 0;
                right = size;
                while (left<=right){
                    mid = left + (right - left)/2;
                    if (ans.get(mid)>=array[i]){
                        right = mid - 1;
                    }else {
                        left = mid + 1;
                    }
                }
                ans.set(left,array[i]);
            }
        }
        System.out.println(size);
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
    }
}
